package com.wuhao.springbootactivemq.topic;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.jms.Topic;
import java.util.UUID;

/**
 * @author: wuhao
 * @since: 2021/11/7 17:24
 */
@Component
@Slf4j
@AllArgsConstructor
public class TopicProduct {

    private JmsMessagingTemplate jmsMessagingTemplate;

    private Topic topic;

    @Scheduled(fixedDelay = 3000)
    public void productTopic() {
        String message = UUID.randomUUID().toString().substring(0, 5);
        jmsMessagingTemplate.convertAndSend(topic, "-------主题消息" + message);
        log.info("-------发送主题Message:{}", message);
    }
}
